var express = require('express');
var router = express.Router();
const classService = require('../service/classService');

router.get('/',async function(req,res){
    let {startDate,endDate,current,pageSize} = req.query;
    let searchObj = {};
    if(startDate){
        searchObj["createDate"] = {$gte:startDate};
    }
    if(endDate){
        searchObj["createDate"] = {...searchObj["createDate"],$lte:endDate};
    }
    let data = await classService.find(searchObj,
            {current:current || 1,pageSize:pageSize || 5});
        
    res.send({data});
});

router.get("/all",async function(req,res){
    let data = await classService.findAll();
    res.send({data});
});
router.get("/:id",async function(req,res){
    let {id} = req.params;
    let data = await classService.findById(id);
    res.send({data});
});



module.exports = router;